<template>
  <div class="component-params">
    <Tab :tabs="tabs" @change="activeChange"></Tab>
    <component :is="configMap[currentTab]"></component>
</div>
</template>

<script>
import { mapGetters } from 'vuex';
import Tab from './components/Tab';
import DefaultConfig from './components/DefaultConfig';
import StyleConfig from './components/StyleConfig';
import DataConfig from './components/DataConfig';

export default {
  name: '',
  components: {
    Tab,
    DefaultConfig,
    StyleConfig,
    DataConfig
  },
  data() {
    return {
      configMap: {
        "config": DefaultConfig,
        "style": StyleConfig,
        "data": DataConfig,
      },
      currentConfig: {},
      tabs: [
        { // 表格的名称数据之类的
          label: '配置',
          value: 'config'
        },
        { // 大小动画什么的
          label: '样式',
          value: 'style'
        },
        { // 交互的数据方法
          label: '数据',
          value: 'data'
        }
      ],
      currentTab: 'config'
    }
  },
  computed: {...mapGetters(['activeId', 'elementList'])},
  watch: {
    activeId() {
      this.currentConfig = this.elementList.find(item => item.id === this.activeId);
    }
  },
  methods: {
    activeChange(value) {
      this.currentTab = value;
    }
  }
}
</script>

<style scoped lang="scss">
.component-params {
  width: 200px;
  height: 100%;
  background-color: #202023;
}

</style>
